<div class="layui-form-item">
    <label class="layui-form-label">{$label}：</label>
    <div class="layui-input-inline">
        <input name="{$name}" lay-verify="{$verify}" lay-verType="tips" lay-reqText="{$placeholder}" id="path_{$path}" placeholder="{$placeholder}" value="{$value}"  readonly class="layui-input">
    </div>
    <div class="layui-input-inline layui-btn-container" style="width: auto;">

        <button type="button" class="layui-btn" id="LAY_{$upload}"><i class="layui-icon"></i>{$btn}</button>

        <a class="layui-btn layui-btn-danger" id="chan_{$choose}">素材库选择</a >

    </div>
</div>



<script >
    layui.use(['element', 'jquery','upload'], function () {
        var element = layui.element;
        var $ = layui.jquery;
        var upload=layui.upload;

        let elem_id='LAY_{$upload}';
        let path='path_{$path}';
        let choose='chan_{$choose}';


        //附件上传
        upload.render({
            elem: '#'+elem_id
            ,url: "{:url('admin/common/UpFiles')}" //文件上传地址
            ,accept: 'file'
            ,exts: 'zip|rar|pdf|txt|doc|docx|ppt|xls|xlsx'
            ,before:function (res) {
                loading = layer.load(2, {
                    shade: [0.2, '#000'] //0.2透明度的白色背景
                });
            }
            ,done: function(data){
                layer.close(loading);
                if (data.code==1){
                    layer.msg(data.msg, {icon: 1, time: 1000},function () {
                        $("#"+path).val(data.path);
                    });
                } else {
                    layer.msg(data.msg, {icon: 5, time: 1000});
                }
            }
            ,error:function (red) {
                layer.close(loading);
                layer.msg("网络错误", {icon: 5, time: 1500});
            }
        });

        // 弹窗选择
        $('#'+choose).click(function () {
            layer.open({
                title:"选择素材图片",
                type: 2,
                area: ["80%", "90%"],
                offset:'auto',
                maxmin : true,
                skin:'layui-layer-molv',
                shade: 0.5,
                content: "{:url('upload/getFiles')}",
                success:function(){
                },
                end:function () {
                    if (typeof(mFsUrls) != "undefined" && mFsUrls.length > 0) {
                        $("#"+path).val(mFsUrls);
                    }
                }
            });
            return false;
        });


    });

</script >
